﻿from datetime import datetime, date
import pandas as pd
import matplotlib.pyplot as plt

plt.rcParams['font.sans-serif'] = ['STSong']
plt.rcParams['axes.unicode_minus'] = False

df = pd.read_csv("top250-1.csv", sep="#", encoding='utf-8',
                 names=['num', 'title', 'year', 'area', 'genre', 'rating_num', 'comment_num', 'href'], header=0)

top_10 = df.head(10)

# 电影名称和上映时间数据
movies = top_10['title']
top_10['year'] = df['year'].str.extract('(\d{4})')  # 提取4位数字作为年份
release_dates = top_10['year'].astype(str)

# 将上映日期转换为datetime对象
release_dates = [datetime.strptime(date, '%Y') for date in release_dates]

# 绘制折线图
plt.plot(movies, release_dates, 'ro')
for movies, release_dates in zip(movies, release_dates):
    plt.text(movies, release_dates, str(release_dates))
# 添加标题和标签
plt.title('电影上映时间')
plt.xlabel('电影名称')
plt.ylabel('上映时间')

# 旋转横轴标签以避免重叠
plt.xticks(rotation=45)

# 显示图形
plt.show()
